package com.tsd.job.service.impl;

import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.job.dao.SysTaskJobExecLogMapper;
import com.tsd.job.entity.SysTaskJobExecLog;
import com.tsd.job.entity.SysTaskJobExecLogExt;
import com.tsd.job.service.SysTaskJobExecLogService;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.entity.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述：SysTaskJobExecLog 服务实现层
 *
 * @author huawei
 * @date 2022/02/24 21:01:20
 */
@Service
public class SysTaskJobExecLogServiceImpl extends BaseServiceImpl implements SysTaskJobExecLogService {

    @Resource
    private SysTaskJobExecLogMapper sysTaskJobExecLogMapper;

    @Override
    public SysTaskJobExecLog getSysTaskJobExecLogById(Long id) throws Exception {
        return sysTaskJobExecLogMapper.selectByPrimaryKey(id);
    }

    @Override
    public SysTaskJobExecLogExt queryBySid(String sid) throws Exception {
        return sysTaskJobExecLogMapper.selectBySid(sid);
    }

    @Override
    public void deleteSysTaskJobExecLogs(List<String> list, SysUser opUser) throws Exception {
        for (String sid : list) {
            SysTaskJobExecLog old = sysTaskJobExecLogMapper.selectBySid(sid);
            super.checkEmpty(old, "该记录不存在");
            super.autoInjectBaseData(old, opUser, TYPE_DELETE);
            sysTaskJobExecLogMapper.updateByPrimaryKeySelective(old);
        }
    }

    @Override
    public void saveSysTaskJobExecLog(SysTaskJobExecLog record, SysUser opUser) throws Exception {
        if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record, opUser, TYPE_CREATE);
            sysTaskJobExecLogMapper.insertSelective(record);
        } else {
            super.autoInjectBaseData(record, opUser, TYPE_UPDATE);
            sysTaskJobExecLogMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public List<SysTaskJobExecLogExt> findSysTaskJobExecLogs(Map<String, Object> params, PageBean page) throws Exception {
        return sysTaskJobExecLogMapper.selectByPage(params, page);
    }

    @Override
    public List<SysTaskJobExecLogExt> findSysTaskJobExecLogs(Map<String, Object> params) throws Exception {
        return sysTaskJobExecLogMapper.selectByParams(params);
    }
}
